package com.example.demo.controller;

import com.example.demo.entity.ResultEntity;
import com.example.demo.service.serviceimpl.ClassificationViewServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RequestMapping("v2/ClassificationView/")
@CrossOrigin
@RestController
public class ClassificationViewController {
    @Resource
    ClassificationViewServiceImpl classificationViewService;
    // 根据ID获取商品详情
    @GetMapping("getClassificationView")
    private ResultEntity getClassificationView(@RequestParam("id") Integer id) {
        ResultEntity resultEntity = new ResultEntity();
        try {
            resultEntity.setCode(0);
            resultEntity.setMsg("获取成功");
            resultEntity.setData(classificationViewService.getClassificationView(id));
        } catch (Exception e) {
            resultEntity.setCode(-1);
            resultEntity.setMsg("商品获取失败");
            e.printStackTrace();
        }
        return resultEntity;
    }

    // 获取所有商品
    @GetMapping("getClassificationViewAll")
    private ResultEntity getClassificationViewAll() {
        ResultEntity resultEntity = new ResultEntity();
        try {
            resultEntity.setCode(0);
            resultEntity.setMsg("获取成功");
            resultEntity.setData(classificationViewService.getClassificationViewAll());
        } catch (Exception e) {
            resultEntity.setCode(-1);
            resultEntity.setMsg("商品列表获取失败");
            e.printStackTrace();
        }
        return resultEntity;
    }
}
